<!DOCTYPE html>
<html>
<head>
    {include file="public/head"}
</head>
<body>
<div class="g-flexview">
    <header class="m-navbar">
        <a href="javascript:history.back();" class="navbar-item">
            <i class="back-ico"></i>
        </a>
        <div class="navbar-center"><span class="navbar-title">我的卖单</span></div>
    </header>
    <div class="g-scrollview">
        <form action="#" method="post">
            <div class="m-cell">
                <div class="cell-item">
                    <div class="cell-left">卖出数量：</div>
                    <div class="cell-right">
                        <input type="number" pattern="[0-9]*" class="cell-input" placeholder="请输入您要卖出的HX币的数量" id="sell" name="sell_num"/>
                    </div>
                </div>
                <div class="cell-item">
                    <div class="cell-left">到账数量：</div>
                    <div class="cell-right">
                        <input type="number" class="cell-input" readonly autocomplete="off" value="0.00" id="account" name="account_num"/>
                    </div>
                </div>
                <div class="cell-item">
                    <div class="cell-left">单价：</div>
                    <div class="cell-right">
                        <input type="number" pattern="[0-9]*" class="cell-input" placeholder="请输入您的单价" id="unit_price" name="unit_price"/>
                    </div>
                </div>
                <div class="cell-item">
                    <div class="cell-left">今日价格区间：</div>
                    <div class="cell-right">
                        <input type="text" class="cell-input" value="{:getStartPrice()}元-{:getEndPrice()}元" readonly/>
                    </div>
                </div>
                <div class="cell-item">
                    <div class="cell-left">手续费：</div>
                    <div class="cell-right">
                        <input type="text" class="cell-input" value="0.00/个币" id="fee" name="fee" readonly/>
                    </div>
                </div>
                <div class="cell-item">
                    <div class="cell-left">总金额：</div>
                    <div class="cell-right">
                        <input type="text" class="cell-input" value="￥0.00" id="sum_money" name="sum_money" readonly/>
                    </div>
                </div>
                <div class="cell-item">
                    <div class="cell-left">手机号：</div>
                    <div class="cell-right">{$user['keep_phone']}</div>
                </div>
                <div class="cell-item">
                    <div class="cell-left">银行卡：</div>
                    <div class="cell-right">{$user['bank_no']}</div>
                </div>
                <div class="cell-item">
                    <div class="cell-left">支付宝：</div>
                    <div class="cell-right">{$user['alipay']}</div>
                </div>
            </div>
            <input type="hidden" name="trade_password" id="trade_password">
        </form>
    </div>
    <button type="button" class="btn-block btn-primary" id="J_OpenKeyBoard">确认创建</button>
</div>
{include file="public/js"}
<script>
    !function ($) {
        $('#sell').bind('input propertychange',function () {
            var fee=$(this).val()*0.2;
            $('#fee').val(fee.toFixed(4)); // 手续费
            $('#account').val($(this).val()-fee); // 到账的币
            $('#sum_money').val((($(this).val()-fee)*$('#unit_price').val()).toFixed(4)); // 总金额
        });
        $('#unit_price').bind('input propertychange',function () {
            $('#sum_money').val((($('#sell').val()-$('#fee').val())*$(this).val()).toFixed(4)); // 总金额
        });
    }(jQuery);
</script>
<div class="m-keyboard" id="J_KeyBoard">
    <!-- 自定义内容区域 -->
    <div style="text-align: right;padding: .15rem .8rem 0;">
        <a href="/index/set/tradePassword.html" style="color: #666;font-size: .24rem;">忘记密码？</a>
    </div>
    <!-- 自定义内容区域 -->
</div>
<script>
    // 安全键盘
    var $keyboard = $('#J_KeyBoard');

    /* 初始化参数 */
    $keyboard.keyBoard({
        disorder: false, /* 是否打乱数字顺序 */
        title: '华兴交易密码' /* 显示标题 */
    });
    /* 打开键盘 */
    $('#J_OpenKeyBoard').on('click', function () {
        $keyboard.keyBoard('open');
    });
    /* 六位密码输入完毕后执行 */
    $keyboard.on('done.ydui.keyboard', function (ret) {
        //console.log('输入的密码是：' + ret.password);
        $('#trade_password').val(ret.password);
        YDUI.dialog.loading.open('验证支付密码');
        $.post('/index/user/newSell',$('form').serialize(),function (res) {
            if (res.code == -1){
                /* 显示错误信息 */
                YDUI.dialog.loading.close();
                $keyboard.keyBoard('error', '对不起，您的支付密码不正确，请重新输入。');
            }
            YDUI.dialog.loading.close();
            $keyboard.keyBoard('close');/* 关闭键盘 */
            dialog.toast(res.msg,'none',1000,function () {
                if (res.code === 2) {
                    location.href='/index/user/sell';
                }
            });
        });
    });
</script>
</body>
</html>